this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.Ui=this.BX.Landing.Ui||{};(function(t,e,n){"use strict";class i extends n.Content{constructor(){super();this.instance=null;this.attr=BX.Landing.Utils.attr;this.join=BX.Landing.Utils.join;this.random=BX.Landing.Utils.random;this.setTextContent=BX.Landing.Utils.setTextContent;this.isPlainObject=BX.Landing.Utils.isPlainObject;this.isString=BX.Landing.Utils.isString;this.textToPlaceholders=BX.Landing.Utils.textToPlaceholders;this.findParent=BX.Landing.Utils.findParent;this.escapeText=BX.Landing.Utils.escapeText;BX.Landing.UI.Panel.Content.apply(this,arguments);this.layout.classList.add("landing-ui-panel-link");this.overlay.classList.add("landing-ui-panel-link");this.appendFooterButton(new BX.Landing.UI.Button.BaseButton("save_block_content",{text:BX.Landing.Loc.getMessage("BLOCK_SAVE"),onClick:this.save.bind(this),className:"landing-ui-button-content-save"}));this.appendFooterButton(new BX.Landing.UI.Button.BaseButton("cancel_block_content",{text:BX.Landing.Loc.getMessage("BLOCK_CANCEL"),onClick:this.hide.bind(this),className:"landing-ui-button-content-cancel"}));document.body.appendChild(this.layout)}static getInstance(){if(!this.instance){this.instance=new BX.Landing.UI.Panel.Link("link_panel",{title:BX.Landing.Loc.getMessage("LANDING_EDIT_LINK")})}return this.instance}show(t){var e;this.title.innerHTML=BX.Landing.Loc.getMessage("LANDING_EDIT_LINK");if(!!t&&t instanceof BX.Landing.Block.Node.Link){this.node=t;e=new BX.Landing.UI.Form.BaseForm({title:this.node.manifest.name});this.field=this.node.getField();e.addField(this.field);this.clear();this.appendForm(e);BX.Landing.UI.Panel.Content.show.call(this);BX.Landing.UI.Panel.EditorPanel.getInstance().hide()}if(!!t&&(t instanceof BX.Landing.Block.Node.Text||t instanceof BX.Landing.UI.Field.Text)){this.range=document.getSelection().getRangeAt(0);this.node=t;this.textField=BX.Landing.UI.Field.BaseField.currentField;if(!!this.textField&&this.textField.isEditable()){this.node=this.textField}var n=this.range.cloneContents().querySelector("a");if(!n){n=this.findParent(this.range.startContainer,{tagName:"A"})}var i="";var a="";if(n){i=n.getAttribute("href");a=n.getAttribute("target")||"_self"}else{this.title.innerHTML=BX.Landing.Loc.getMessage("LANDING_CREATE_LINK")}e=new BX.Landing.UI.Form.BaseForm({title:""});BX.remove(e.header);var s=[BX.Landing.UI.Field.LinkURL.TYPE_BLOCK,BX.Landing.UI.Field.LinkURL.TYPE_PAGE];if(BX.Landing.Main.getInstance().options.params.type==="STORE"){s.push(BX.Landing.UI.Field.LinkURL.TYPE_CATALOG)}this.field=new BX.Landing.UI.Field.Link({title:BX.Landing.Loc.getMessage("FIELD_LINK_TEXT_LABEL"),content:{text:this.textToPlaceholders(this.escapeText(n?n.innerText:this.range.toString())),href:this.escapeText(i),target:this.escapeText(a)},options:{siteId:BX.Landing.Main.getInstance().options.site_id,landingId:BX.Landing.Main.getInstance().id,filter:{"=TYPE":BX.Landing.Main.getInstance().options.params.type}},allowedTypes:s});e.addField(this.field);this.clear();this.appendForm(e);BX.Landing.UI.Panel.Content.show.call(this)}}save(){if(this.field.isChanged()){if(!!this.node&&this.node instanceof BX.Landing.Block.Node.Link){this.node.setValue(this.field.getValue())}else{var t=this.field.getValue();document.getSelection().removeAllRanges();document.getSelection().addRange(this.range);this.node.enableEdit();var e=this.escapeText(this.join(t.href,this.random()));var n=document.getSelection();document.execCommand("createLink",false,e);var i=n.anchorNode.parentElement.parentElement.parentElement.querySelector(this.join('[href="',e,'"]'));if(i){this.attr(i,"href",t.href);this.attr(i,"target",t.target);if(this.isString(t.text)){if(t.text.includes("{{name}}")){this.field.hrefInput.getPlaceholderData(t.href).then(function(e){i.innerHTML=t.text.replace(new RegExp("{{name}}"),'<span data-placeholder="name">'+e.name+"</span>")}.bind(this))}else{this.setTextContent(i,t.text)}}if(this.isPlainObject(t.attrs)){this.attr(i,t.attrs)}}}}this.hide()}}t.Link=i})(this.BX.Landing.Ui.Panel=this.BX.Landing.Ui.Panel||{},BX,BX.Landing.UI.Panel);
//# sourceMappingURL=link.bundle.map.js